const data = [
  {
    name: 'feifei',
    _id: '3171104101',
    password: '123456',
    email: '123456789@qq.com',
    qqNumber: '123456789',
    telephone: '12345678911',
    avatar: '1'
  },
  {
    name: 'liang',
    _id: '3171104102',
    password: '123456',
    email: '123456789@qq.com',
    qqNumber: '123456789',
    telephone: '12345678911',
    avatar: '1'
  },
  {
    name: 'jun',
    _id: '3171104103',
    password: '123456',
    email: '123456789@qq.com',
    qqNumber: '123456789',
    telephone: '12345678911',
    avatar: '1'
  },
  {
    name: 'ming',
    _id: '3171104104',
    password: '123456',
    email: '123456789@qq.com',
    qqNumber: '123456789',
    telephone: '12345678911',
    avatar: '1'
  }
]
export default [
  // 获取用户列表
  {
    url: '/admins',
    type: 'get',
    response: config => {
      return data
    }
  },
  // 删除指定用户
  {
    url: '/admin',
    type: 'delete',
    response: config => {
      const { path } = config
      const id = path.split('/')[3]
      var index
      for (var i in data) {
        if (data[i]._id === id) {
          index = i
          break
        }
      }
      data.splice(index, 1)
      return data
    }
  },
  // 查找指定用户
  {
    url: '/admin',
    type: 'get',
    response: config => {
      const { path } = config
      const id = path.split('/')[3]
      var index
      for (var i in data) {
        if (data[i]._id === id) {
          index = i
          break
        }
      }
      return data[index]
    }
  },
  // 保存指定用户
  {
    url: '/admin',
    type: 'put',
    response: config => {
      const {
        name,
        password,
        email,
        qqNumber,
        telephone,
        avatar
      } = config.body
      const { path } = config
      const id = path.split('/')[3]
      var index
      for (var i in data) {
        if (data[i]._id === id) {
          index = i
          data[index].name = name
          data[index].password = password
          data[index].email = email
          data[index].qqNumber = qqNumber
          data[index].telephone = telephone
          data[index].avatar = avatar
          break
        }
      }
      return data[index]
    }
  },
  // 新建用户
  {
    url: '/admin',
    type: 'post',
    response: config => {
      console.log(config.query)
      const {
        _id,
        name,
        password,
        email,
        qqNumber,
        telephone,
        avatar
      } = config.body
      console.log(
        name + password + email + qqNumber + telephone + avatar + _id
      )
      const person = {
        name: name,
        _id: _id,
        password: password,
        email: email,
        qqNumber: qqNumber,
        telephone: telephone,
        avatar: avatar
      }
      data.push(person)
      return data
    }
  }
]
